package controller;

import model.User;

import java.util.ArrayList;
import java.util.List;

public class UserController {
    private List<User> userList = new ArrayList<>();

    public void addUser(User user) {
        userList.add(user);
    }

    public User getUser(String username) {
        return userList.stream().filter(u -> u.getUsername().equals(username)).findFirst().orElse(null);
    }

    public void updateUser(User user) {
        for (int i = 0; i < userList.size(); i++) {
            if (userList.get(i).getUsername().equals(user.getUsername())) {
                userList.set(i, user);
                break;
            }
        }
    }

    public void deleteUser(String username) {
        userList.removeIf(u -> u.getUsername().equals(username));
    }

    public List<User> getAllUsers() {
        return userList;
    }
}